import Taro, { requirePlugin } from "@tarojs/taro";
var plugin = requirePlugin("WechatSI");
let manager = plugin.getRecordRecognitionManager();

export const useSoundsTool = () => {
  function transform(text, callback) {
    Taro.showLoading({
      title: "请等待...",
    });
    manager.onRecognize = function (res: any) {
      console.log("current result", res.result);
    };
    manager.onStop = function (res: any) {
      console.log("record file path", res.tempFilePath);
      console.log("result", res.result);
      Taro.showToast({
        title: "转换成功",
      });
      callback(res.result)
    };
    manager.onStart = function (res: any) {
      console.log("成功开始录音识别", res);
      Taro.hideLoading();
      Taro.showToast({
        title: "成功开始录音识别",
      });
      text.value = '我说完了'
    };
    manager.onError = function (res: any) {
      console.error("error msg", res.msg);
    };
    manager.start({ duration: 30000, lang: "zh_CN" });
  }


  function close() {
    manager.stop();
    Taro.showLoading({
      title: "请等待...",
    });
  }


  return {
    transform,
    close
  }
};
